home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / Xconq 7.0d16 / Xconq 7.0d16 src / src / mplay.c < prev    next >
Encoding:
Text File  |  1993-12-20  |  53.5 KB  |  118 lines  |  [TEXT/MPS ]

  1. nited = FALSE;
  2.  
  3. mplayer_init(side)
  4. Side *side;
  5. {
  6.     Unit *unit;
  7.  
  8.     /* (should do this only when absolutely needed - mplayer might
  9.        never actually be used) */
  10.     if (!mplayerinited) {
  11.     mplayer_init_shared();
  12.     mplayerinited = TRUE;
  13.     Dprintf("One mplayer AI is %d bytes.\n", sizeof(Strategy));
  14.     }
  15.     /* Make sure a strategy object exists. */
  16.     if (mplayer(side) == NULL) create_strategy(side);
  17.     /* If the side has no units at the moment, it doesn't really need to
  18.        plan. */
  19.     if (!side_has_units(side)) return;
  20.     analyze_the_game(side);
  21.     /* Reset plans of any units that were not doing anything. */
  22.     for_all_side_units(side, unit) {
  23.         if (in_play(unit) && unit->plan && unit->plan->aicontrol) {
  24.         unit->plan->asleep = FALSE;
  25.         unit->plan->reserve = FALSE;
  26.         unit->plan->waitingfortasks = FALSE;
  27.         if (unit->plan->type == PLAN_PASSIVE) {
  28.         unit->plan->type = PLAN_NONE;
  29.         }
  30.         }
  31.     }
  32. }
  33.  
  34. /* At the beginning of each turn, make plans and review the situation. */
  35.  
  36. mplayer_init_turn(side)
  37. Side *side;
  38. {
  39.     int x, y;
  40.  
  41.     /* Cases where we no longer need to run. */
  42.     if (!side->ingame) return;
  43.     /* A side without units hasn't got anything to do but wait. */
  44.     /* (should account for possible units on controlled sides) */
  45.     if (!side_has_units(side)) return;
  46.     /* Mplayers in a hacked game are reluctant to play,
  47.        unless they're being debugged. */
  48.     if (compromised && !DebugM) return;
  49.     update_all_progress_displays("ai turn init start", side->id);
  50.     DMprintf("%s mplayer init turn\n", side_desig(side));
  51.     /* Make sure a strategy object exists. */
  52.     if (mplayer(side) == NULL) create_strategy(side);
  53.     /* Look over the game design we're playing with. */
  54.     analyze_the_game(side);
  55.     /* If this game is one that can be won, as opposed to
  56.        just dinking around, figure how to win it. */
  57.     if (mplayer(side)->trytowin) {
  58.     /* Check out the current goal tree first. */
  59.     review_goals(side);
  60.     /* Goal analysis might have triggered resignation. */
  61.     if (!side->ingame) return;
  62.     /* Check out all the theaters. */
  63.     review_theaters(side);
  64.     /* Check out all of our units. */
  65.     review_units(side);
  66.     /* Decide on the new current plan. */
  67.     update_side_strategy(side);
  68.     /* Propagate this to individual unit plans. */
  69.     update_unit_plans(side);
  70.     } else {
  71.     update_unit_plans_randomly(side);
  72.     }
  73.     update_all_progress_displays("" /* "ai turn init done" */, side->id);
  74.     DMprintf("%s mplayer done with init turn\n", side_desig(side));
  75. }
  76.  
  77. /* Create and install an entirely new strategy object for the side. */
  78.  
  79. create_strategy(side)
  80. Side *side;
  81. {
  82.     int u, t, dir;
  83.     Strategy *strategy = (Strategy *) xmalloc(sizeof(Strategy));
  84.  
  85.     /* Put the specific structure into a generic slot. */
  86.     side->ai = (struct a_ai *) strategy;
  87.     strategy->type = mplayertype;
  88.     /* Allocate a table of pointers to theaters, for access via small numbers
  89.        rather than full pointers. */
  90.     strategy->theatertable = (Theater **) xmalloc(127 * sizeof(Theater *));
  91.     /* Allocate a layer of indexes into the theater table. */
  92.     strategy->areatheaters = malloc_area_layer(char);
  93.     /* Allocate random things. */
  94.     /* Arrays for unit types. */
  95.     strategy->actualmix = (short *) xmalloc(numutypes * sizeof(short));
  96.     strategy->expectedmix = (short *) xmalloc(numutypes * sizeof(short));
  97.     strategy->idealmix = (short *) xmalloc(numutypes * sizeof(short));
  98.     /* Arrays for terrain types. */
  99.     strategy->terrainguess = (short *) xmalloc(numttypes * sizeof(short));
  100.     /* Set everything to correct initial values. */
  101.     reset_strategy(side);
  102. }
  103.  
  104. /* Put all the right initial values into the strategy, but don't allocate anything. */
  105.  
  106. reset_strategy(side)
  107. Side *side;
  108. {
  109.     int u, t, dir;
  110.     Strategy *strategy = (Strategy *) side->ai;
  111.  
  112.     /* Remember when we did this. */
  113.     strategy->creationdate = curturn;
  114.     /* Null out various stuff. */
  115.     strategy->numgoals = 0;
  116.     strategy->theaters = NULL;
  117.     /* Actually we start with no theaters, but it's convenient to leave entry 0
  118.        in the theater table point